import time

from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


class Base():
    def __init__(self):
        cap = {
            "platformName": "Android",#平台名称
            "appium:deviceName": "emulator-5554",#设备名
            "appium:automationName": "uiautomator2",#驱动名称
            "appium:appPackage": "com.achievo.vipshop",#包名
            "appium:appActivity": ".homepage.activity.MainActivity",#主活动名
            "appium:noReset": True
        }
        self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',cap)
        #隐式等待
        self.driver.implicitly_wait(20)
    #查找元素
    def find_ele(self,loc):
        ele = self.driver.find_element(*loc)
        return ele
    #滑动
    def hua(self,a,b,c,d):
        self.driver.swipe(a,b,c,d,300)
    #轻敲
    def qiao(self,a,b):
        self.driver.tap([(a,b)],300)
    #截屏
    def jie(self,a):
        self.driver.save_screenshot(a)
    #显示等待
    def wat(self,loc):
        ele = WebDriverWait(self.driver,300).until(EC.element_to_be_clickable(loc))
        return ele
    #退出
    def tui(self):
        self.driver.quit()
    def jiep(self,a):
        t = time.strftime("%Y%m%d%H%M%S",time.localtime())
        self.driver.save_screenshot(t+a)